using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Entities;
using BUS;
using Utility;

public partial class Admin_PhuongThucThanhToanUpdate : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            LoadData();
        }
    }
    private void LoadData()
    {
        try
        {
            int iD = int.Parse(Request.QueryString["iD"].ToString());
            txt_maphuongthucthanhtoan.Text = iD.ToString();
            tbPhuongThucThanhToan phuongthucthanhtoan = tbPhuongThucThanhToanBUS.GetByID(iD);
            txt_tenphuongthucthanhtoan.Text = phuongthucthanhtoan.TenPTTT;
            img_hinh.ImageUrl = "~/Photos/Thumb/" + phuongthucthanhtoan.Hinh;
        }
        catch
        {
            Response.Redirect("~/Admin/PhuongThucThanhToanDanhSach.aspx");
        }
    }

    protected void btn_sua_Click(object sender, EventArgs e)
    {
        try
        {
            int iD = int.Parse(Request.QueryString["iD"].ToString());
            tbPhuongThucThanhToan  phuongthucthanhtoan = tbPhuongThucThanhToanBUS.GetByID(iD);
            phuongthucthanhtoan.TenPTTT = txt_tenphuongthucthanhtoan.Text;
            if (fu_hinh.HasFile)
            {
                string filename = DateTime.Now.Ticks.ToString() + "_" + fu_hinh.FileName;
                fu_hinh.SaveAs(Server.MapPath("~/Photos/" + filename));

                System.Drawing.Image img = System.Drawing.Image.FromFile(
                    Server.MapPath("~/Photos/" + filename));
                ImageUtility.MakeThumbnailPhoto(img, 100, 100, Server.MapPath("~/Photos/Thumb/"), filename);

                if (phuongthucthanhtoan .Hinh  != "no_images.jpg")
                {
                    System.IO.File.Delete(Server.MapPath("~/Photos/" + phuongthucthanhtoan .Hinh ));
                    System.IO.File.Delete(Server.MapPath("~/Photos/Thumb/" + phuongthucthanhtoan.Hinh));
                }
                phuongthucthanhtoan .Hinh  = filename;
            }
            tbPhuongThucThanhToanBUS.Update(phuongthucthanhtoan);
        }
        catch
        {
        }
        Response.Redirect("~/Admin/PhuongThucThanhToanDanhSach.aspx");
        Response.Redirect(Request.RawUrl);
    }
}
